package net.jedi.cfire;

import jsr166y.forkjoin.ForkJoinPool;
import jsr166y.forkjoin.RecursiveTask;

public class Test extends RecursiveTask<Integer> {
	final int n;
	
	Test(int n) {
		this.n = n;
	}

	@Override
	protected Integer compute() {
		// test with Fibonacci
		if (n <= 1)
			return n;
		Test f1 = new Test(n - 1);
		f1.fork();
		Test f2 = new Test(n - 2);
		return f2.forkJoin() + f1.join();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ForkJoinPool pool = new ForkJoinPool();
		int ret = pool.invoke(new Test(38));	// 38 -> two cores for a few seconds
		System.out.println("Result: "+ret);
	}

}
